<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0050)http://www.w3.org/TR/2009/WD-webdatabase-20091222/ -->
<HTML lang="en-US-x-Hixie"><HEAD><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><TITLE>Web SQL Database</TITLE><STYLE type="text/css">
   pre { margin-left: 2em; white-space: pre-wrap; }
   h2 { margin: 3em 0 1em 0; }
   h3 { margin: 2.5em 0 1em 0; }
   h4 { margin: 2.5em 0 0.75em 0; }
   h5, h6 { margin: 2.5em 0 1em; }
   h1 + h2, h1 + h2 + h2 { margin: 0.75em 0 0.75em; }
   h2 + h3, h3 + h4, h4 + h5, h5 + h6 { margin-top: 0.5em; }
   p { margin: 1em 0; }
   hr:not(.top) { display: block; background: none; border: none; padding: 0; margin: 2em 0; height: auto; }
   dl, dd { margin-top: 0; margin-bottom: 0; }
   dt { margin-top: 0.75em; margin-bottom: 0.25em; clear: left; }
   dt + dt { margin-top: 0; }
   dd dt { margin-top: 0.25em; margin-bottom: 0; }
   dd p { margin-top: 0; }
   dd dl + p { margin-top: 1em; }
   dd table + p { margin-top: 1em; }
   p + * > li, dd li { margin: 1em 0; }
   dt, dfn { font-weight: bold; font-style: normal; }
   dt dfn { font-style: italic; }
   pre, code { font-size: inherit; font-family: monospace; font-variant: normal; }
   pre strong { color: black; font: inherit; font-weight: bold; background: yellow; }
   pre em { font-weight: bolder; font-style: normal; }
   @media screen { code { color: orangered; } code :link, code :visited { color: inherit; } }
   var sub { vertical-align: bottom; font-size: smaller; position: relative; top: 0.1em; }
   table { border-collapse: collapse; border-style: hidden hidden none hidden; }
   table thead { border-bottom: solid; }
   table tbody th:first-child { border-left: solid; }
   table tbody th { text-align: left; }
   table td, table th { border-left: solid; border-right: solid; border-bottom: solid thin; vertical-align: top; padding: 0.2em; }
   blockquote { margin: 0 0 0 2em; border: 0; padding: 0; font-style: italic; }

   .bad, .bad *:not(.XXX) { color: gray; border-color: gray; background: transparent; }
   .matrix, .matrix td { border: none; text-align: right; }
   .matrix { margin-left: 2em; }
   .dice-example { border-collapse: collapse; border-style: hidden solid solid hidden; border-width: thin; margin-left: 3em; }
   .dice-example caption { width: 30em; font-size: smaller; font-style: italic; padding: 0.75em 0; text-align: left; }
   .dice-example td, .dice-example th { border: solid thin; width: 1.35em; height: 1.05em; text-align: center; padding: 0; }

   .toc dfn, h1 dfn, h2 dfn, h3 dfn, h4 dfn, h5 dfn, h6 dfn { font: inherit; }
   img.extra { float: right; }
   pre.idl { border: solid thin; background: #EEEEEE; color: black; padding: 0.5em 1em; }
   pre.idl :link, pre.idl :visited { color: inherit; background: transparent; }
   pre.css { border: solid thin; background: #FFFFEE; color: black; padding: 0.5em 1em; }
   pre.css:first-line { color: #AAAA50; }
   dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #EEFFEE; }
   hr + dl.domintro, div.impl + dl.domintro { margin-top: 2.5em; margin-bottom: 1.5em; }
   dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
   dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
   dl.domintro dd p { margin: 0.5em 0; }
   dl.switch { padding-left: 2em; }
   dl.switch > dt { text-indent: -1.5em; }
   dl.switch > dt:before { content: '\21AA'; padding: 0 0.5em 0 0; display: inline-block; width: 1em; text-align: right; line-height: 0.5em; }
   dl.triple { padding: 0 0 0 1em; }
   dl.triple dt, dl.triple dd { margin: 0; display: inline }
   dl.triple dt:after { content: ':'; }
   dl.triple dd:after { content: '\A'; white-space: pre; }
   .diff-old { text-decoration: line-through; color: silver; background: transparent; }
   .diff-chg, .diff-new { text-decoration: underline; color: green; background: transparent; }
   a .diff-new { border-bottom: 1px blue solid; }

   h2 { page-break-before: always; }
   h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
   h1 + h2, hr + h2.no-toc { page-break-before: auto; }

   p > span:not([title=""]):not([class="XXX"]):not([class="impl"]), li > span:not([title=""]):not([class="XXX"]):not([class="impl"]) { border-bottom: solid #9999CC; }

   div.head { margin: 0 0 1em; padding: 1em 0 0 0; }
   div.head p { margin: 0; }
   div.head h1 { margin: 0; }
   div.head .logo { float: right; margin: 0 1em; }
   div.head .logo img { border: none } /* remove border from top image */
   div.head dl { margin: 1em 0; }
   div.head p.copyright, div.head p.alt { font-size: x-small; font-style: oblique; margin: 0; }

   body > .toc > li { margin-top: 1em; margin-bottom: 1em; }
   body > .toc.brief > li { margin-top: 0.35em; margin-bottom: 0.35em; }
   body > .toc > li > * { margin-bottom: 0.5em; }
   body > .toc > li > * > li > * { margin-bottom: 0.25em; }
   .toc, .toc li { list-style: none; }

   .brief { margin-top: 1em; margin-bottom: 1em; line-height: 1.1; }
   .brief li { margin: 0; padding: 0; }
   .brief li p { margin: 0; padding: 0; }

   .category-list { margin-top: -0.75em; margin-bottom: 1em; line-height: 1.5; }
   .category-list::before { content: '\21D2\A0'; font-size: 1.2em; font-weight: 900; }
   .category-list li { display: inline; }
   .category-list li:not(:last-child)::after { content: ', '; }
   .category-list li > span, .category-list li > a { text-transform: lowercase; }
   .category-list li * { text-transform: none; } /* don't affect <code> nested in <a> */

   .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
   .XXX > :first-child { margin-top: 0; }
   p .XXX { line-height: 3em; }
   .annotation { border: solid thin black; background: #0C479D; color: white; position: relative; margin: 8px 0 20px 0; }
   .annotation:before { position: absolute; left: 0; top: 0; width: 100%; height: 100%; margin: 6px -6px -6px 6px; background: #333333; z-index: -1; content: ''; }
   .annotation :link, .annotation :visited { color: inherit; }
   .annotation :link:hover, .annotation :visited:hover { background: transparent; }
   .annotation span { border: none ! important; }
   .note { color: green; background: transparent; font-family: sans-serif; }
   .warning { color: red; background: transparent; }
   .note, .warning { font-weight: bolder; font-style: italic; }
   p.note, div.note { padding: 0.5em 2em; }
   span.note { padding: 0 2em; }
   .note p:first-child, .warning p:first-child { margin-top: 0; }
   .note p:last-child, .warning p:last-child { margin-bottom: 0; }
   .warning:before { font-style: normal; }
   p.note:before { content: 'Note: '; }
   p.warning:before { content: '\26A0 Warning! '; }

   .bookkeeping:before { display: block; content: 'Bookkeeping details'; font-weight: bolder; font-style: italic; }
   .bookkeeping { font-size: 0.8em; margin: 2em 0; }
   .bookkeeping p { margin: 0.5em 2em; display: list-item; list-style: square; }

   h4 { position: relative; z-index: 3; }
   h4 + .element, h4 + div + .element { margin-top: -2.5em; padding-top: 2em; }
   .element {
     background: #EEEEFF;
     color: black;
     margin: 0 0 1em 0.15em;
     padding: 0 1em 0.25em 0.75em;
     border-left: solid #9999FF 0.25em;
     position: relative;
     z-index: 1;
   }
   .element:before {
     position: absolute;
     z-index: 2;
     top: 0;
     left: -1.15em;
     height: 2em;
     width: 0.9em;
     background: #EEEEFF;
     content: ' ';
     border-style: none none solid solid;
     border-color: #9999FF;
     border-width: 0.25em;
   }

   .example { display: block; color: #222222; background: #FCFCFC; border-left: double; margin-left: 2em; padding-left: 1em; }
   td > .example:only-child { margin: 0 0 0 0.1em; }

   .tall-and-narrow {
     font-size: 0.6em;
     column-width: 25em;
     column-gap: 1em;
     -moz-column-width: 25em;
     -moz-column-gap: 1em;
     -webkit-column-width: 25em;
     -webkit-column-gap: 1em;
   }

   ul.domTree, ul.domTree ul { padding: 0 0 0 1em; margin: 0; }
   ul.domTree li { padding: 0; margin: 0; list-style: none; position: relative; }
   ul.domTree li li { list-style: none; }
   ul.domTree li:first-child::before { position: absolute; top: 0; height: 0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
   ul.domTree li:not(:last-child)::after { position: absolute; top: 0; bottom: -0.6em; left: -0.75em; width: 0.5em; border-style: none none solid solid; content: ''; border-width: 0.1em; }
   ul.domTree span { font-style: italic; font-family: serif; }
   ul.domTree .t1 code { color: purple; font-weight: bold; }
   ul.domTree .t2 { font-style: normal; font-family: monospace; }
   ul.domTree .t2 .name { color: black; font-weight: bold; }
   ul.domTree .t2 .value { color: blue; font-weight: normal; }
   ul.domTree .t3 code, .domTree .t4 code, .domTree .t5 code { color: gray; }
   ul.domTree .t7 code, .domTree .t8 code { color: green; }
   ul.domTree .t10 code { color: teal; }

   #configUI { position: absolute; z-index: 20; top: 10em; right: 1em; width: 11em; font-size: small; }
   #configUI p { margin: 0.5em 0; padding: 0.3em; background: #EEEEEE; color: black; border: inset thin; }
   #configUI p label { display: block; }
   #configUI #updateUI, #configUI .loginUI { text-align: center; }
   #configUI input[type=button] { display: block; margin: auto; }
  </STYLE><LINK href="./Web SQL Database_files/W3C-WD" rel="stylesheet" type="text/css"></HEAD><BODY><DIV class="head">
   <P><A href="http://www.w3.org/"><IMG alt="W3C" height="48" src="./Web SQL Database_files/w3c_home" width="72"></A></P>
   <H1>Web SQL Database</H1>
   <H2 class="no-num no-toc" id="w3c-working-draft-22-december-2009">W3C Working Draft 22 December 2009</H2> <!-- ZZZ -->

   <DL><DT>This Version:</DT>
    <DD><A href="./Web SQL Database_files/Web SQL Database.htm">http://www.w3.org/TR/2009/WD-webdatabase-20091222/</A></DD>
    <DT>Latest Published Version:</DT>
    <DD><A href="http://www.w3.org/TR/webdatabase/">http://www.w3.org/TR/webdatabase/</A></DD>
    <DT>Latest Editor's Draft:</DT>
    <DD><A href="http://dev.w3.org/html5/webdatabase/">http://dev.w3.org/html5/webdatabase/</A></DD>
<!-- ZZZ: add the new version after it has shipped-->
    <DT>Previous Versions:</DT>
    <DD><A href="http://www.w3.org/TR/2009/WD-webstorage-20090423/">http://www.w3.org/TR/2009/WD-webstorage-20090423/</A> <!-- yes, storage, not db -->
    </DD><DD><A href="http://www.w3.org/TR/2009/WD-webdatabase-20090910/">http://www.w3.org/TR/2009/WD-webdatabase-20090910/</A></DD>
    <DD><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091029/">http://www.w3.org/TR/2009/WD-webdatabase-20091029/</A></DD>
<!-- :ZZZ -->
    <DT>Editors:</DT>
    <DD><A href="mailto:ian@hixie.ch">Ian Hickson</A>, Google, Inc.</DD>
   </DL><P class="copyright"><A href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</A>
   © 2009 <A href="http://www.w3.org/"><ABBR title="World Wide
   Web Consortium">W3C</ABBR></A><SUP>®</SUP> (<A href="http://www.csail.mit.edu/"><ABBR title="Massachusetts
   Institute of Technology">MIT</ABBR></A>, <A href="http://www.ercim.org/"><ABBR title="European Research
   Consortium for Informatics and Mathematics">ERCIM</ABBR></A>, <A href="http://www.keio.ac.jp/">Keio</A>), All Rights Reserved. W3C
   <A href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</A>,
   <A href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</A>
   and <A href="http://www.w3.org/Consortium/Legal/copyright-documents">document
   use</A> rules apply.</P>
  </DIV><HR class="top"><H2 class="no-num no-toc" id="abstract">Abstract</H2><P>This specification defines an API for storing data in databases
  that can be queried using a variant of SQL.</P><H2 class="no-num no-toc" id="status-of-this-document">Status of This document</H2><!-- intro boilerplate (required) --><P><EM>This section describes the status of this document at the
  time of its publication. Other documents may supersede this
  document. A list of current W3C publications and the most recently
  formally published revision of this technical report can be found in
  the <A href="http://www.w3.org/TR/">W3C technical reports index</A>
  at http://www.w3.org/TR/.</EM></P><!-- where to send feedback (required) --><P>If you wish to make comments regarding this document, please send
  them to <A href="mailto:public-webapps@w3.org">public-webapps@w3.org</A>
  (<A href="mailto:public-webapps-request@w3.org?subject=subscribe">subscribe</A>,
  <A href="http://lists.w3.org/Archives/Public/public-webapps/">archives</A>)

  <!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING SENTENCE TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST -->  
  or <A href="mailto:whatwg@whatwg.org">whatwg@whatwg.org</A> (<A href="http://lists.whatwg.org/listinfo.cgi/whatwg-whatwg.org">subscribe</A>,
  <A href="http://lists.whatwg.org/pipermail/whatwg-whatwg.org/">archives</A>),
  <!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING SENTENCE TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST -->

  or submit them using <A href="http://www.w3.org/Bugs/Public/enter_bug.cgi?product=WebAppsWG&component=Web%20Storage">our
  public bug database</A>.

  All feedback is welcome.</P><!-- stability (required) --><P>Implementors should be aware that this specification is not
  stable. <STRONG>Implementors who are not taking part in the
  discussions are likely to find the specification changing out from
  under them in incompatible ways.</STRONG> Vendors interested in
  implementing this specification before it eventually reaches the
  Candidate Recommendation stage should join the aforementioned
  mailing lists and take part in the discussions.</P><P class="XXX">This specification has reached an impasse: all
  interested implementors have used the same SQL backend (Sqlite), but
  we need multiple independent implementations to proceed along a
  standardisation path. Until another implementor is interested in
  implementing this spec, the description of the SQL dialect has been
  left as simply a reference to Sqlite, which isn't acceptable for a
  standard. Should you be an implementor interested in implementing an
  independent SQL backend, please contact the editor so that he can
  write a specification for the dialect, thus allowing this
  specification to move forward.</P><!-- version history or list of changes (required) --><P>The latest stable version of the editor's draft of this
  specification is always available on <A href="http://dev.w3.org/html5/webdatabase/Overview.html">the W3C CVS
  server</A>. Change tracking for this document is available at the
  following location:</P><UL><LI>CVS log: <A href="http://dev.w3.org/cvsweb/html5/webdatabase/Overview.html">http://dev.w3.org/cvsweb/html5/webdatabase/Overview.html</A></LI>
  </UL><!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- relationship to other work (required) --><P>This specification is automatically generated from the
  corresponding section in the HTML5 specification's source document,
  as hosted in the <A href="http://svn.whatwg.org/webapps/">WHATWG
  Subversion repository</A>. Detailed change history for all of HTML5,
  including the parts that form this specification, can be found at
  the following locations:</P><!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING PARAGRAPH TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- UNDER NO CIRCUMSTANCES IS THE FOLLOWING LIST TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><UL><LI>Twitter messages (non-editorial changes only): <A href="http://twitter.com/WHATWG">http://twitter.com/WHATWG</A></LI>
   <LI>Interactive Web interface: <A href="http://html5.org/tools/web-apps-tracker">http://html5.org/tools/web-apps-tracker</A></LI>
   <LI>Commit-Watchers mailing list: <A href="http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org">http://lists.whatwg.org/listinfo.cgi/commit-watchers-whatwg.org</A></LI>
   <LI>Subversion interface: <A href="http://svn.whatwg.org/webapps/">http://svn.whatwg.org/webapps/</A></LI>
  </UL><!-- UNDER NO CIRCUMSTANCES IS THE PRECEDING LIST TO BE REMOVED OR EDITED WITHOUT TALKING TO IAN FIRST --><!-- status of document, group responsible (required) --><P>The W3C <A href="http://www.w3.org/2008/webapps/">Web Apps
  Working Group</A> is the W3C working group responsible for this
  specification's progress along the W3C Recommendation track.
  This specification is the 22 December 2009 <!--Last Call--> Working Draft. <!--The Last Call review period will end on 30 June 2010.-->

  </P><!-- required patent boilerplate --><P>This document was produced by a group operating under the <A href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5
  February 2004 W3C Patent Policy</A>. W3C maintains a <A href="http://www.w3.org/2004/01/pp-impl/42538/status" rel="disclosure">public list of
  any patent disclosures</A> made in connection with the deliverables
  of the group; that page also includes instructions for disclosing a
  patent. An individual who has actual knowledge of a patent which the
  individual believes contains <A href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
  Claim(s)</A> must disclose the information in accordance with <A href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
  6 of the W3C Patent Policy</A>.</P><H2 class="no-num no-toc" id="contents">Table of Contents</H2>
<!--begin-toc-->
<OL class="toc">
 <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#introduction"><SPAN class="secno">1 </SPAN>Introduction</A></LI>
 <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#conformance-requirements"><SPAN class="secno">2 </SPAN>Conformance requirements</A>
  <OL>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dependencies"><SPAN class="secno">2.1 </SPAN>Dependencies</A></LI></OL></LI>
 <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#terminology"><SPAN class="secno">3 </SPAN>Terminology</A></LI>
 <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sql"><SPAN class="secno">4 </SPAN>The API</A>
  <OL>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#databases"><SPAN class="secno">4.1 </SPAN>Databases</A></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#parsing-and-processing-sql-statements"><SPAN class="secno">4.2 </SPAN>Parsing and processing SQL statements</A></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#asynchronous-database-api"><SPAN class="secno">4.3 </SPAN>Asynchronous database API</A>
    <OL>
     <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#executing-sql-statements"><SPAN class="secno">4.3.1 </SPAN>Executing SQL statements</A></LI>
     <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#processing-model"><SPAN class="secno">4.3.2 </SPAN>Processing model</A></LI></OL></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#synchronous-database-api"><SPAN class="secno">4.4 </SPAN>Synchronous database API</A>
    <OL>
     <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#executing-sql-statements-0"><SPAN class="secno">4.4.1 </SPAN>Executing SQL statements</A></LI></OL></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database-query-results"><SPAN class="secno">4.5 </SPAN>Database query results</A></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#errors-and-exceptions"><SPAN class="secno">4.6 </SPAN>Errors and exceptions</A></LI></OL></LI>
 <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#web-sql"><SPAN class="secno">5 </SPAN>Web SQL</A></LI>
 <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#disk-space"><SPAN class="secno">6 </SPAN>Disk space</A></LI>
 <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#privacy"><SPAN class="secno">7 </SPAN>Privacy</A>
  <OL>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#user-tracking"><SPAN class="secno">7.1 </SPAN>User tracking</A></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sensitivity-of-data"><SPAN class="secno">7.2 </SPAN>Sensitivity of data</A></LI></OL></LI>
 <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#security"><SPAN class="secno">8 </SPAN>Security</A>
  <OL>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dns-spoofing-attacks"><SPAN class="secno">8.1 </SPAN>DNS spoofing attacks</A></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#cross-directory-attacks"><SPAN class="secno">8.2 </SPAN>Cross-directory attacks</A></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#implementation-risks"><SPAN class="secno">8.3 </SPAN>Implementation risks</A></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sql-and-user-agents"><SPAN class="secno">8.4 </SPAN>SQL and user agents</A></LI>
   <LI><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sql-injection"><SPAN class="secno">8.5 </SPAN>SQL injection</A></LI></OL></LI>
 <LI><A class="no-num" href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#references">References</A></LI></OL>
<!--end-toc--><HR><!-- Feature requests for future versions (v2):
        * deleting databases
        * determining how much storage room is left
        * handling the database getting corrupted
  --><H2 id="introduction"><SPAN class="secno">1 </SPAN>Introduction</H2><P><I>This section is non-normative.</I></P><P>This specification introduces a set of APIs to manipulate
  client-side databases using SQL.</P><P>The API is asynchronous, so authors are likely to find anonymous
  functions (lambdas) very useful in using this API.</P><P>Here is an example of a script using this API. First, a function
  <CODE title="">prepareDatabase()</CODE> is defined. This function
  tries to create the database if necessary, giving it one table
  called "docids" with two columns ("id" and "name"). If it is
  successful, or if the table doesn't need creating, it calls a
  section function, <CODE title="">getDatabase()</CODE>, which obtains
  a handle to the database, and then calls the function to do the
  actual work, in this case <CODE title="">showDocCount()</CODE>.</P><PRE>function prepareDatabase(ready, error) {
  return openDatabase('documents', '1.0', 'Offline document storage', 5*1024*1024, function (db) {
    db.changeVersion('', '1.0', function (t) {
      t.executeSql('CREATE TABLE docids (id, name)');
    }, error);
  });
}

function showDocCount(db, span) {
  db.readTransaction(function (t) {
    t.executeSql('SELECT COUNT(*) AS c FROM docids', [], function (t, r) {
      span.textContent = r.rows[0].c;
    }, function (t, e) {
      // couldn't read database
      span.textContent = '(unknown: ' + e.message + ')';
    });
  });
}

prepareDatabase(function(db) {
  // got database
  var span = document.getElementById('doc-count');
  showDocCount(db, span);
}, function (e) {
  // error getting database
  alert(e.message);
});</PRE><HR><P>The <CODE title="dom-sqltransaction-executeSql"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqltransaction-executesql">executeSql()</A></CODE> method has
  an argument intended to allow variables to be substituted into
  statements without risking SQL injection vulnerabilities:</P><PRE>db.readTransaction(function (t) {
  t.executeSql('SELECT title, author FROM docs WHERE id=?', [id], function (t, data) {
    report(data.rows[0].title, data.rows[0].author);
  });
});</PRE><HR><P>Sometimes, there might be an arbitrary number of variables to
  substitute in. Even in these case, the right solution is to
  construct the query using only "?" characters, and then to pass the
  variables in as the second argument:</P><PRE>function findDocs(db, resultCallback) {
  var q = "";
  for each (var i in labels)
    q += (q == "" ? "" : ", ") + "?";
  db.readTransaction(function (t) {
    t.executeSql('SELECT id FROM docs WHERE label IN (' + q + ')', labels, function (t, data) {
      resultCallback(data);
    });
  });
}</PRE><H2 id="conformance-requirements"><SPAN class="secno">2 </SPAN>Conformance requirements</H2><P>All diagrams, examples, and notes in this specification are
  non-normative, as are all sections explicitly marked non-normative.
  Everything else in this specification is normative.</P><P>The key words "MUST", "MUST NOT", "REQUIRED", <!--"SHALL", "SHALL
  NOT",--> "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and
  "OPTIONAL" in the normative parts of this document are to be
  interpreted as described in RFC2119. For readability, these words do
  not appear in all uppercase letters in this specification. <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsRFC2119">[RFC2119]</A></P><P>Requirements phrased in the imperative as part of algorithms
  (such as "strip any leading space characters" or "return false and
  abort these steps") are to be interpreted with the meaning of the
  key word ("must", "should", "may", etc) used in introducing the
  algorithm.</P><P>Some conformance requirements are phrased as requirements on
  attributes, methods or objects. Such requirements are to be
  interpreted as requirements on user agents.</P><P>Conformance requirements phrased as algorithms or specific steps
  may be implemented in any manner, so long as the end result is
  equivalent. (In particular, the algorithms defined in this
  specification are intended to be easy to follow, and not intended to
  be performant.)</P><P>The only conformance class defined by this specification is user
  agents.</P><P>User agents may impose implementation-specific limits on
  otherwise unconstrained inputs, e.g. to prevent denial of service
  attacks, to guard against running out of memory, or to work around
  platform-specific limitations.</P><H3 id="dependencies"><SPAN class="secno">2.1 </SPAN>Dependencies</H3><P>This specification relies on several other underlying
  specifications.</P><DL><DT>HTML5</DT>

   <DD>

    <P>Many fundamental concepts from HTML5 are used by this
    specification. <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsHTML5">[HTML5]</A></P>

   </DD>

   <DT>WebIDL</DT>

   <DD>

    <P>The IDL blocks in this specification use the semantics of the
    WebIDL specification. <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsWEBIDL">[WEBIDL]</A></P>

   </DD>

  </DL><H2 id="terminology"><SPAN class="secno">3 </SPAN>Terminology</H2><P>The construction "a <CODE title="">Foo</CODE> object", where
  <CODE title="">Foo</CODE> is actually an interface, is sometimes
  used instead of the more accurate "an object implementing the
  interface <CODE title="">Foo</CODE>".</P><P>The term DOM is used to refer to the API set made available to
  scripts in Web applications, and does not necessarily imply the
  existence of an actual <CODE>Document</CODE> object or of any other
  <CODE>Node</CODE> objects as defined in the DOM Core
  specifications. <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsDOMCORE">[DOMCORE]</A></P><P>An IDL attribute is said to be <EM>getting</EM> when its value is
  being retrieved (e.g. by author script), and is said to be
  <EM>setting</EM> when a new value is assigned to it.</P><P>The term "JavaScript" is used to refer to ECMA262, rather than
  the official term ECMAScript, since the term JavaScript is more
  widely known. <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsECMA262">[ECMA262]</A></P><H2 id="sql"><SPAN class="secno">4 </SPAN>The API</H2><H3 id="databases"><SPAN class="secno">4.1 </SPAN>Databases</H3><P>Each <I>origin</I> has an associated set of databases. Each
  database has a name and a current version. There is no way to
  enumerate or delete the databases available for an origin from this
  API.</P><P class="note">Each database has one version at a time; a database
  can't exist in multiple versions at once. Versions are intended to
  allow authors to manage schema changes incrementally and
  non-destructively, and without running the risk of old code (e.g. in
  another browser window) trying to write to a database with incorrect
  assumptions.</P><PRE class="idl">[Supplemental, NoInterfaceObject]
interface <SPAN>WindowDatabase</SPAN> {
  <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A> <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-opendatabase" title="dom-opendatabase">openDatabase</A>(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#databasecallback">DatabaseCallback</A> creationCallback);
};
<SPAN>Window</SPAN> implements <SPAN>WindowDatabase</SPAN>;

[Supplemental, NoInterfaceObject]
interface <SPAN>WorkerUtilsDatabase</SPAN> {
  <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A> <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-opendatabase" title="dom-opendatabase">openDatabase</A>(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#databasecallback">DatabaseCallback</A> creationCallback);
  <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#databasesync">DatabaseSync</A> <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-opendatabase-sync" title="dom-opendatabase-sync">openDatabaseSync</A>(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#databasecallback">DatabaseCallback</A> creationCallback);
};
<SPAN>WorkerUtils</SPAN> implements <SPAN>WorkerUtilsDatabase</SPAN>;

[Callback=FunctionOnly, NoInterfaceObject]
interface <DFN id="databasecallback">DatabaseCallback</DFN> {
  void <SPAN title="dom-databasecallback-handleEvent">handleEvent</SPAN>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A> database);
};</PRE><P>The <DFN id="dom-opendatabase" title="dom-opendatabase"><CODE>openDatabase()</CODE></DFN> method on
  the <CODE>Window</CODE> and <CODE>WorkerUtils</CODE> interfaces and
  the <DFN id="dom-opendatabase-sync" title="dom-opendatabase-sync"><CODE>openDatabaseSync()</CODE></DFN>
  method on the <CODE>WorkerUtils</CODE> interface take the following
  arguments: a database name, a database version, a display name, an
  estimated size — in bytes — of the data that will be
  stored in the database, and optionally a callback to be invoked if
  the database has not yet been created. The callback, if provided, is
  intended to be used to call <CODE title="dom-database-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-changeversion">changeVersion()</A></CODE>; the
  callback is invoked with the database having the empty string as its
  version regardless of the given database version. If the callback is
  not provided, the database is created with the given database
  version as its version.</P><P>When invoked, these methods must run the following steps, with all
  but the last two steps being run atomically:</P><OL><LI>

    <P>The user agent may raise a <CODE>SECURITY_ERR</CODE> exception
    instead of returning a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A></CODE> object if the request
    violates a policy decision (e.g. if the user agent is configured
    to not allow the page to open databases).</P>

   </LI>

   <LI>

    <P>For the method on the <CODE>Window</CODE> object: let <VAR title="">origin</VAR> be the <SPAN>origin</SPAN> of the
    <SPAN>active document</SPAN> of the <SPAN>browsing context</SPAN>
    of the <CODE>Window</CODE> object on which the method was
    invoked.</P>

    <P>For the methods on the <CODE>WorkerUtils</CODE> object: let
    <VAR title="">origin</VAR> be the <SPAN>origin</SPAN> of the
    scripts in the worker.</P>

   </LI>

   <LI><P>If the database version provided is not the empty string,
   and there is already a database with the given name from the origin
   <VAR title="">origin</VAR>, but the database has a different
   version than the version provided, then throw an
   <CODE>INVALID_STATE_ERR</CODE> exception and abort these
   steps.</P></LI>

   <LI>

    <P>If no database with the given name from the origin <VAR title="">origin</VAR> exists, then create the database and let
    <VAR title="">created</VAR> be true. If a callback was passed to
    the method, then set the new database's version to the empty
    string. Otherwise, set the new database's version to the given
    database version.</P>

    <P>Otherwise, if a database with the given name already exists,
    let <VAR title="">created</VAR> be false.</P>

   </LI>

   <LI>

    <P>For the <CODE title="dom-opendatabase"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-opendatabase">openDatabase()</A></CODE>
    methods: let <VAR title="">result</VAR> be a newly constructed
    <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A></CODE> object representing the database with the
    given database name from the origin <VAR title="">origin</VAR>.</P>

    <P>For the <CODE title="dom-opendatabase-sync"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-opendatabase-sync">openDatabaseSync()</A></CODE> method:
    let <VAR title="">result</VAR> be a newly constructed
    <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#databasesync">DatabaseSync</A></CODE> object representing the database with
    the given database name from the origin <VAR title="">origin</VAR>.</P>

   </LI>

   <LI>

    <P>If <VAR title="">created</VAR> is false or if no callback was
    passed to the method, skip this step. Otherwise:</P>

    <P>For the <CODE title="dom-opendatabase"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-opendatabase">openDatabase()</A></CODE>
    methods: <SPAN>queue a task</SPAN> to to invoke the callback with
    <VAR title="">result</VAR> as its only argument.</P>

    <P>For the <CODE title="dom-opendatabase-sync"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-opendatabase-sync">openDatabaseSync()</A></CODE> method:
    invoke the callback with <VAR title="">result</VAR> as its only
    argument. If the callback throws an exception, rethrow that
    exception and abort these steps.</P>

   </LI>

   <LI>

    <P>Return <VAR title="">result</VAR>.</P>

   </LI>

  </OL><P>All strings including the empty string are valid database
  names. Database names must be compared in a
  <SPAN>case-sensitive</SPAN> manner.</P><P class="note">Implementations can support this even in
  environments that only support a subset of all strings as database
  names by mapping database names (e.g. using a hashing algorithm) to
  the supported set of names.</P><P>The version that the database was opened with is the <DFN id="concept-database-expected-version" title="concept-database-expected-version">expected version</DFN> of
  this <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A></CODE> or <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#databasesync">DatabaseSync</A></CODE> object. It
  can be the empty string, in which case there is no expected version
  — any version is fine.</P><P>User agents are expected to use the display name and the
  estimated database size to optimize the user experience. For
  example, a user agent could use the estimated size to suggest an
  initial quota to the user. This allows a site that is aware that it
  will try to use hundreds of megabytes to declare this upfront,
  instead of the user agent prompting the user for permission to
  increase the quota every five megabytes.</P><H3 id="parsing-and-processing-sql-statements"><SPAN class="secno">4.2 </SPAN>Parsing and processing SQL statements</H3><P>When the user agent is to <DFN id="preprocess-the-sql-statement" title="preprocess the SQL
  statement">preprocess a SQL statement</DFN> <VAR title="">sqlStatement</VAR> with an array of arguments <VAR title="">arguments</VAR>, it must run the following steps:</P><OL><LI><P>Parse <VAR title="">sqlStatement</VAR> as a SQL statement,
   with the exception that U+003F QUESTION MARK characters (?) can be
   used in place of SQL literals in the statement. <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsSQL">[SQL]</A></P></LI>

   <LI>

    <P>Bind each <CODE title="">?</CODE> placeholder with the value of
    the argument in the <VAR title="">arguments</VAR> array with the
    same position. (So the first <CODE title="">?</CODE> placeholder
    gets bound to the first value in the <VAR title="">arguments</VAR>
    array, and generally the <VAR title="">n</VAR>th <CODE title="">?</CODE> placeholder gets bound to the <VAR title="">n</VAR>th value in the <VAR title="">arguments</VAR>
    array.)</P>

    <P class="note">Binding the <CODE title="">?</CODE> placeholders
    is done at the literal level, not as string concatenations, so
    this provides a way to dynamically insert parameters into a
    statement without risk of a SQL injection attack.</P>

    <P>The result is <VAR title="">the statement</VAR>.</P>

   </LI>

   <LI><P>If the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A></CODE> object that the
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A></CODE> or <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE>
   object was created from has an <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#concept-database-expected-version" title="concept-database-expected-version">expected version</A>
   that is neither the empty string nor the actual version of the
   database, then mark <VAR title="">the statement</VAR> as
   bogus. (<A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlerror-code-2" title="dom-sqlerror-code-2">Error code
   2</A>.)</P></LI>

   <LI>

    <P>Otherwise, if the syntax of <VAR title="">sqlStatement</VAR> is
    not valid (except for the use of <CODE title="">?</CODE>
    characters in the place of literals), or the statement uses
    features that are not supported (e.g. due to security reasons), or
    the number of items in the <VAR title="">arguments</VAR> array is
    not equal to the number of <CODE title="">?</CODE> placeholders in
    the statement, or the statement cannot be parsed for some other
    reason, then mark <VAR title="">the statement</VAR> as
    bogus. (<A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlerror-code-5" title="dom-sqlerror-code-5">Error code
    5</A>.)</P>

    <P>User agents must consider statements that use the <CODE title="">BEGIN</CODE>, <CODE title="">COMMIT</CODE>, and <CODE title="">ROLLBACK</CODE> SQL features as being unsupported (and thus
    will mark them as bogus), so as to not let these statements
    interfere with the explicit transactions managed by the database API
    itself.</P>

   </LI>

   <LI id="modifications-fail-if-read-only">

    <P>Otherwise, if the <I>mode</I> that was used to create the
    <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A></CODE> or <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE>
    object is read-only but the statement's main verb can modify the
    database, mark the statement as bogus. (<A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlerror-code-5" title="dom-sqlerror-code-5">Error code 5</A>.)</P>

    <P class="note">Only the statement's main verb (e.g. <CODE title="">UPDATE</CODE>, <CODE title="">SELECT</CODE>, <CODE title="">DROP</CODE>) is considered here. Thus, a statement like
    "<CODE title="">UPDATE test SET id=0 WHERE 0=1</CODE>" would be
    treated as potentially modifying the database for the purposes
    of this step, even though it could never in fact have any
    side-effects.</P>

   </LI>

   <LI><P>Return <VAR title="">the statement</VAR>.</P></LI>

  </OL><P>The user agent must act as if the database was hosted in an
  otherwise completely empty environment with no resources. For
  example, attempts to read from or write to the file system will
  fail.</P><P class="note">A future version of this specification will probably
  define the exact SQL subset required in more detail.</P><H3 id="asynchronous-database-api"><SPAN class="secno">4.3 </SPAN>Asynchronous database API</H3><PRE class="idl">interface <DFN id="database">Database</DFN> {
  void <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-transaction" title="dom-database-transaction">transaction</A>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactioncallback">SQLTransactionCallback</A> callback, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionerrorcallback">SQLTransactionErrorCallback</A> errorCallback, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlvoidcallback">SQLVoidCallback</A> successCallback);
  void <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-readtransaction" title="dom-database-readTransaction">readTransaction</A>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactioncallback">SQLTransactionCallback</A> callback, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionerrorcallback">SQLTransactionErrorCallback</A> errorCallback, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlvoidcallback">SQLVoidCallback</A> successCallback);

  readonly attribute DOMString <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-version" title="dom-database-version">version</A>;
  void <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-changeversion" title="dom-database-changeVersion">changeVersion</A>(in DOMString oldVersion, in DOMString newVersion, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactioncallback">SQLTransactionCallback</A> callback, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionerrorcallback">SQLTransactionErrorCallback</A> errorCallback, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlvoidcallback">SQLVoidCallback</A> successCallback);
};

[Callback=FunctionOnly, NoInterfaceObject]
interface <DFN id="sqlvoidcallback">SQLVoidCallback</DFN> {
  void <SPAN title="dom-sqlvoidcallback-handleEvent">handleEvent</SPAN>();
};

[Callback=FunctionOnly, NoInterfaceObject]
interface <DFN id="sqltransactioncallback">SQLTransactionCallback</DFN> {
  void <SPAN title="dom-sqltransactioncallback-handleEvent">handleEvent</SPAN>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A> transaction);
};

[Callback=FunctionOnly, NoInterfaceObject]
interface <DFN id="sqltransactionerrorcallback">SQLTransactionErrorCallback</DFN> {
  void <SPAN title="dom-sqltransactionerrorcallback-handleEvent">handleEvent</SPAN>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlerror">SQLError</A> error);
};</PRE><P>The <DFN id="dom-database-transaction" title="dom-database-transaction"><CODE>transaction()</CODE></DFN>
  and <DFN id="dom-database-readtransaction" title="dom-database-readTransaction"><CODE>readTransaction()</CODE></DFN>
  methods takes one to three arguments. When called, these methods must
  immediately return and then asynchronously run the <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#transaction-steps">transaction
  steps</A> with the <I>transaction callback</I> being the first
  argument, the <I>error callback</I> being the second argument, if
  any, the <I>success callback</I> being the third argument, if any,
  and with no <I>preflight operation</I> or <I>postflight
  operation</I>.</P><P>For the <CODE title="dom-database-transaction"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-transaction">transaction()</A></CODE> method, the
  <I>mode</I> must be read/write. For the <CODE title="dom-database-readTransaction"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-readtransaction">readTransaction()</A></CODE>
  method, the <I>mode</I> must be read-only.</P><P>On getting, the <DFN id="dom-database-version" title="dom-database-version"><CODE>version</CODE></DFN> attribute
  must return the current version of the database (as opposed to the
  <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#concept-database-expected-version" title="concept-database-expected-version">expected
  version</A> of the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A></CODE> object).</P><P>The <DFN id="dom-database-changeversion" title="dom-database-changeVersion"><CODE>changeVersion()</CODE></DFN>
  method allows scripts to atomically verify the version number and
  change it at the same time as doing a schema update. When the method
  is invoked, it must immediately return, and then asynchronously run
  the <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#transaction-steps">transaction steps</A> with the <I>transaction
  callback</I> being the third argument, the <I>error callback</I>
  being the fourth argument, the <I>success callback</I> being the
  fifth argument, the <I>preflight operation</I> being the
  following:</P><OL><LI><P>Check that the value of the first argument to the <CODE title="dom-database-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-changeversion">changeVersion()</A></CODE> method
   exactly matches the database's actual version. If it does not, then
   the <I>preflight operation</I> fails.</P></LI>

  </OL><P>...the <I>postflight operation</I> being the following:</P><OL><LI>Change the database's actual version to the value of the second
   argument to the <CODE title="dom-database-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-changeversion">changeVersion()</A></CODE>
   method.</LI>

   <LI>Change the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A></CODE> object's expected version to
   the value of the second argument to the <CODE title="dom-database-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-changeversion">changeVersion()</A></CODE>
   method.</LI>

  </OL><P>...and the <I>mode</I> being read/write.</P><P>If any of the optional arguments are omitted, then they must be
  treated as if they were null.</P><H4 id="executing-sql-statements"><SPAN class="secno">4.3.1 </SPAN>Executing SQL statements</H4><P>The <CODE title="dom-database-transaction"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-transaction">transaction()</A></CODE>,
  <CODE title="dom-database-readTransaction"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-readtransaction">readTransaction()</A></CODE>,
  and <CODE title="dom-database-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-changeversion">changeVersion()</A></CODE>
  methods invoke callbacks with <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A></CODE>
  objects.</P><PRE class="idl">typedef sequence&lt;any&gt; <DFN id="objectarray">ObjectArray</DFN>;

interface <DFN id="sqltransaction">SQLTransaction</DFN> {
  void <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqltransaction-executesql" title="dom-sqltransaction-executeSql">executeSql</A>(in DOMString sqlStatement, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#objectarray">ObjectArray</A> arguments, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlstatementcallback">SQLStatementCallback</A> callback, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlstatementerrorcallback">SQLStatementErrorCallback</A> errorCallback);
};

[Callback=FunctionOnly, NoInterfaceObject]
interface <DFN id="sqlstatementcallback">SQLStatementCallback</DFN> {
  void <SPAN title="dom-sqlstatementcallback-handleEvent">handleEvent</SPAN>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A> transaction, in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultset">SQLResultSet</A> resultSet);
};

[Callback=FunctionOnly, NoInterfaceObject]
interface <DFN id="sqlstatementerrorcallback">SQLStatementErrorCallback</DFN> {
  boolean <SPAN title="dom-sqlstatementerrorcallback-handleEvent">handleEvent</SPAN>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A> transaction, in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlerror">SQLError</A> error);
};</PRE><P>When the <DFN id="dom-sqltransaction-executesql" title="dom-sqltransaction-executeSql"><CODE>executeSql(<VAR title="">sqlStatement</VAR>, <VAR title="">arguments</VAR>, <VAR title="">callback</VAR>, <VAR title="">errorCallback</VAR>)</CODE></DFN> method is invoked, the
  user agent must run the following algorithm. (This algorithm is
  relatively simple in that it doesn't actually execute any SQL
  — the bulk of the work is actually done as part of the
  <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#transaction-steps">transaction steps</A>.)</P><OL><LI><P>If the method was not invoked during the execution of a
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactioncallback">SQLTransactionCallback</A></CODE>,
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlstatementcallback">SQLStatementCallback</A></CODE>, or
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlstatementerrorcallback">SQLStatementErrorCallback</A></CODE> then raise an
   <CODE>INVALID_STATE_ERR</CODE> exception. (Calls from inside a
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionerrorcallback">SQLTransactionErrorCallback</A></CODE> thus raise an
   exception. The <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionerrorcallback">SQLTransactionErrorCallback</A></CODE> handler is
   only called once a transaction has failed, and no SQL statements
   can be added to a failed transaction.)</P></LI>

   <LI>

    <P><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#preprocess-the-sql-statement">Preprocess the SQL statement</A> given as the first
    argument to the method (<VAR title="">sqlStatement</VAR>), using
    the second argument to the method as the <VAR title="">arguments</VAR> array, to obtain <VAR title="">the
    statement</VAR>.</P>

    <P>If the second argument is omitted or null, then treat the <VAR title="">arguments</VAR> array as empty.</P>

   </LI>

   <LI><P>Queue up <VAR title="">the statement</VAR> in the
   transaction, along with the third argument (if any) as the
   statement's result set callback and the fourth argument (if any) as
   the error callback.</P></LI>

  </OL><H4 id="processing-model"><SPAN class="secno">4.3.2 </SPAN>Processing model</H4><P>The <DFN id="transaction-steps">transaction steps</DFN> are as follows. These steps must
  be run asynchronously. These steps are invoked with a <I>transaction
  callback</I>, optionally an <I>error callback</I>, optionally a
  <I>success callback</I>, optionally a <I>preflight operation</I>,
  optionally a <I>postflight operation</I>, and with a <I>mode</I>
  that is either read/write or read-only.</P><OL><LI><P>Open a new SQL transaction to the database, and create a
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A></CODE> object that represents that
   transaction. If the <I>mode</I> is read/write, the transaction must
   have an exclusive write lock over the entire database. If the
   <I>mode</I> is read-only, the transaction must have a shared read
   lock over the entire database. The user agent should wait for an
   appropriate lock to be available.</P></LI>

   <LI><P>If an error occurred in the opening of the transaction
   (e.g. if the user agent failed to obtain an appropriate lock after
   an appropriate delay), jump to the last step.</P></LI>

   <LI><P>If a <I>preflight operation</I> was defined for this
   instance of the transaction steps, run that. If it fails, then jump
   to the last step. (This is basically a hook for the <CODE title="dom-database-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-changeversion">changeVersion()</A></CODE>
   method.)</P></LI>

   <LI><P>If the <I>transaction callback</I> is not null, <SPAN>queue
   a task</SPAN> to invoke the <I>transaction callback</I> with the
   aforementioned <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A></CODE> object as its only
   argument, and wait for that task to be run.</P></LI>

   <LI><P>If the callback raised an exception, jump to the last
   step.</P></LI>

   <LI><P>While there are any statements queued up in the transaction,
   perform the following steps for each queued up statement in the
   transaction, oldest first. Each statement has a statement,
   optionally a result set callback, and optionally an error
   callback.</P>

    <OL><LI><P>If the statement is marked as bogus, jump to the "in case
     of error" steps below.</P></LI>

     <LI><P>Execute the statement in the context of the transaction.
     <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsSQL">[SQL]</A></P>

     </LI><LI><P>If the statement failed, jump to the "in case of error"
     steps below.</P></LI>

     <LI><P>Create a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultset">SQLResultSet</A></CODE> object that represents
     the result of the statement.</P></LI>

     <LI><P>If the statement has a result set callback that is not
     null, <SPAN>queue a task</SPAN> to invoke it with the
     <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A></CODE> object as its first argument and the
     new <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultset">SQLResultSet</A></CODE> object as its second argument, and
     wait for that task to be run.</P></LI>

     <LI><P>If the callback was invoked and raised an exception, jump
     to the last step in the overall steps.</P></LI>

     <LI><P>Move on to the next statement, if any, or onto the next
     overall step otherwise.</P></LI>

    </OL><P>In case of error (or more specifically, if the above substeps
    say to jump to the "in case of error" steps), run the following
    substeps:</P>

    <OL><LI><P>If the statement had an associated error callback that is
     not null, then <SPAN>queue a task</SPAN> to invoke that error
     callback with the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransaction">SQLTransaction</A></CODE> object and a newly
     constructed <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlerror">SQLError</A></CODE> object that represents the
     error that caused these substeps to be run as the two arguments,
     respectively, and wait for the task to be run.</P></LI>

     <LI><P>If the error callback returns false, then move on to the
     next statement, if any, or onto the next overall step
     otherwise.</P></LI>

     <LI><P>Otherwise, the error callback did not return false, or
     there was no error callback. Jump to the last step in the overall
     steps.</P></LI>

    </OL></LI>

   <LI>

    <P>If a <I>postflight operation</I> was defined for this instance
    of the transaction steps, then: as one atomic operation, commit
    the transaction and run the <I>postflight operation</I>. If either
    fails, then do neither, and instead jump to the last step. (This
    is basically a hook for the <CODE title="dom-database-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-changeversion">changeVersion()</A></CODE>
    method.)</P>

    <P>Otherwise: commit the transaction and run the <I>postflight
    operation</I>. If an error occurred in the committing of the
    transaction, jump to the last step.</P>

   </LI>

   <LI><P><SPAN>Queue a task</SPAN> to invoke the <I>success
   callback</I>, if it is not null.</P></LI>

   <LI><P>End these steps. The next step is only used when something
   goes wrong.</P></LI>

   <LI><P><SPAN>Queue a task</SPAN> to invoke the transaction's
   <I>error callback</I>, if it is not null, with a newly constructed
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlerror">SQLError</A></CODE> object that represents the last error to have
   occurred in this transaction. Rollback the transaction. Any
   still-pending statements in the transaction are discarded.</P></LI>

  </OL><P>The <SPAN>task source</SPAN> for these <SPAN title="concept-task">tasks</SPAN> is the <DFN id="database-access-task-source">database access task
  source</DFN>.</P><H3 id="synchronous-database-api"><SPAN class="secno">4.4 </SPAN>Synchronous database API</H3><PRE class="idl">interface <DFN id="databasesync">DatabaseSync</DFN> {
  void <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-transaction" title="dom-database-sync-transaction">transaction</A>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsynccallback">SQLTransactionSyncCallback</A> callback);
  void <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-readtransaction" title="dom-database-sync-readTransaction">readTransaction</A>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsynccallback">SQLTransactionSyncCallback</A> callback);

  readonly attribute DOMString <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-version" title="dom-database-sync-version">version</A>;
  void <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-changeversion" title="dom-database-sync-changeVersion">changeVersion</A>(in DOMString oldVersion, in DOMString newVersion, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsynccallback">SQLTransactionSyncCallback</A> callback);
};

[Callback=FunctionOnly, NoInterfaceObject]
interface <DFN id="sqltransactionsynccallback">SQLTransactionSyncCallback</DFN> {
  void <SPAN title="dom-sqltransactionsynccallback-handleEvent">handleEvent</SPAN>(in <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A> transaction);
};</PRE><P>The <DFN id="dom-database-sync-transaction" title="dom-database-sync-transaction"><CODE>transaction()</CODE></DFN>
  and <DFN id="dom-database-sync-readtransaction" title="dom-database-sync-readTransaction"><CODE>readTransaction()</CODE></DFN>
  methods must run the following steps:</P><OL><LI><P>If the method was the <CODE title="dom-database-sync-transaction"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-transaction">transaction()</A></CODE> method,
   <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#create-a-sqltransactionsync-object">create a <CODE>SQLTransactionSync</CODE> object</A> for a
   read/write transaction. Otherwise, <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#create-a-sqltransactionsync-object">create a
   <CODE>SQLTransactionSync</CODE> object</A> for a read-only
   transaction. In either case, if this throws an exception, then
   rethrow it and abort these steps. Otherwise, let <VAR title="">transaction</VAR> be the newly created
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE> object.</P></LI>

   <LI><P>If the first argument is null, rollback the transaction,
   throw a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlexception">SQLException</A></CODE> exception, and abort these
   steps. (<A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlerror-code-0" title="dom-sqlerror-code-0">Error code
   0</A>.)</P></LI>

   <LI><P>Invoke the callback given by the first argument, passing it
   the <VAR title="">transaction</VAR> object as its only
   argument.</P></LI>

   <LI><P>Mark the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE> object as <I title="">stale</I>.</P>

   </LI><LI><P>If the callback was terminated by an exception, then
   rollback the transaction, rethrow that exception, and abort these
   steps.</P></LI>

   <LI><P>Commit the transaction.</P></LI>

   <LI><P>If an error occurred in the committing of the transaction,
   rollback the transaction, throw a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlexception">SQLException</A></CODE>
   exception, and abort these steps.</P></LI>

  </OL><P>On getting, the <DFN id="dom-database-sync-version" title="dom-database-sync-version"><CODE>version</CODE></DFN>
  attribute must return the current version of the database (as
  opposed to the <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#concept-database-expected-version" title="concept-database-expected-version">expected version</A> of
  the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#databasesync">DatabaseSync</A></CODE> object).</P><P>The <DFN id="dom-database-sync-changeversion" title="dom-database-sync-changeVersion"><CODE>changeVersion()</CODE></DFN>
  method allows scripts to atomically verify the version number and
  change it at the same time as doing a schema update. When the method
  is invoked, it must run the following steps:</P><OL><LI><P><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#create-a-sqltransactionsync-object">Create a <CODE>SQLTransactionSync</CODE> object</A>
   for a read/write transaction. If this throws an exception, then
   rethrow it and abort these steps. Otherwise, let <VAR title="">transaction</VAR> be the newly created
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE> object.</P></LI>

   <LI><P>Check that the value of the first argument to the <CODE title="dom-database-sync-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-changeversion">changeVersion()</A></CODE>
   method exactly matches the database's actual version. If it does
   not, then throw a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlexception">SQLException</A></CODE> exception and abort
   these steps. (<A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlerror-code-2" title="dom-sqlerror-code-2">Error code
   2</A>.)</P></LI>

   <LI><P>If the third argument is not null, invoke the callback given
   by the third argument, passing it the <VAR title="">transaction</VAR> object as its only argument.</P></LI>

   <LI><P>Mark the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE> object as <I title="">stale</I>.</P>

   </LI><LI><P>If the callback was terminated by an exception, then
   rollback the transaction, rethrow the exception, and abort these
   steps.</P></LI>

   <LI><P>Commit the transaction.</P></LI>

   <LI><P>If an error occurred in the committing of the transaction,
   rollback the transaction, throw a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlexception">SQLException</A></CODE>
   exception, and abort these steps.</P></LI>

   <LI>Change the database's actual version to the value of the second
   argument to the <CODE title="dom-database-sync-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-changeversion">changeVersion()</A></CODE>
   method.</LI>

   <LI>Change the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A></CODE> object's expected version to
   the value of the second argument to the <CODE title="dom-database-sync-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-changeversion">changeVersion()</A></CODE>
   method.</LI>

  </OL><HR><P>When the user agent is to <DFN id="create-a-sqltransactionsync-object">create a
  <CODE>SQLTransactionSync</CODE> object</DFN> for a transaction that
  is either read/write or read-only, it must run the following
  steps:</P><OL><LI><P>Open a new SQL transaction to the database, and create a
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE> object that represents that
   transaction. If the <I>mode</I> is read/write, the transaction must
   have an exclusive write lock over the entire database. If the
   <I>mode</I> is read-only, the transaction must have a shared read
   lock over the entire database. The user agent should wait for an
   appropriate lock to be available.</P></LI>

   <LI><P>If an error occurred in the opening of the transaction
   (e.g. if the user agent failed to obtain an appropriate lock after
   an appropriate delay), throw a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlexception">SQLException</A></CODE> exception
   and abort these steps.</P></LI>

   <LI><P>Return the newly created <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE>
   object.</P></LI>

  </OL><H4 id="executing-sql-statements-0"><SPAN class="secno">4.4.1 </SPAN>Executing SQL statements</H4><P>The <CODE title="dom-database-sync-transaction"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-transaction">transaction()</A></CODE>, <CODE title="dom-database-sync-readTransaction"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-readtransaction">readTransaction()</A></CODE>,
  and <CODE title="dom-database-sync-changeVersion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-changeversion">changeVersion()</A></CODE>
  methods invoke callbacks that are passed
  <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE> objects.</P><PRE class="idl">// typedef sequence&lt;any&gt; <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#objectarray">ObjectArray</A>;

interface <DFN id="sqltransactionsync">SQLTransactionSync</DFN> {
  <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultset">SQLResultSet</A> <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqltransaction-sync-executesql" title="dom-sqltransaction-sync-executeSql">executeSql</A>(in DOMString sqlStatement, in optional <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#objectarray">ObjectArray</A> arguments);
};</PRE><P>A <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE> object is initially <I title="">fresh</I>, but it will be marked as <I title="">stale</I>
  once it has been committed or rolled back.</P><P>When the <DFN id="dom-sqltransaction-sync-executesql" title="dom-sqltransaction-sync-executeSql"><CODE>executeSql(<VAR title="">sqlStatement</VAR>, <VAR title="">arguments</VAR>)</CODE></DFN> method is invoked, the user
  agent must run the following algorithm:</P><OL><LI><P>If the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqltransactionsync">SQLTransactionSync</A></CODE> object is <I title="">stale</I>, then throw an <CODE>INVALID_STATE_ERR</CODE>
   exception.</P></LI>

   <LI>

    <P><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#preprocess-the-sql-statement">Preprocess the SQL statement</A> given as the first
    argument to the method (<VAR title="">sqlStatement</VAR>), using
    the second argument to the method as the <VAR title="">arguments</VAR> array, to obtain <VAR title="">the
    statement</VAR>.</P>

    <P>If the second argument is omitted or null, then treat the <VAR title="">arguments</VAR> array as empty.</P>

   </LI>

   <LI><P>If the statement is marked as bogus, throw a
   <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlexception">SQLException</A></CODE> exception.</P></LI>

   <LI><P>Execute the statement in the context of the transaction.
   <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsSQL">[SQL]</A></P>

   </LI><LI><P>If the statement failed, throw a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlexception">SQLException</A></CODE>
   exception.</P></LI>

   <LI><P>Create a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultset">SQLResultSet</A></CODE> object that represents
   the result of the statement.</P></LI>

   <LI><P>Return the newly created <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultset">SQLResultSet</A></CODE>
   object.</P></LI>

  </OL><H3 id="database-query-results"><SPAN class="secno">4.5 </SPAN>Database query results</H3><P>The <CODE title="dom-sqltransaction-executeSql"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqltransaction-executesql">executeSql()</A></CODE>
  method invokes its callback with a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultset">SQLResultSet</A></CODE> object
  as an argument.</P><PRE class="idl">interface <DFN id="sqlresultset">SQLResultSet</DFN> {
  readonly attribute long <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultset-insertid" title="dom-SQLResultSet-insertId">insertId</A>;
  readonly attribute long <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultset-rowsaffected" title="dom-SQLResultSet-rowsAffected">rowsAffected</A>;
  readonly attribute <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultsetrowlist">SQLResultSetRowList</A> <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultset-rows" title="dom-SQLResultSet-rows">rows</A>;
};</PRE><P>The <DFN id="dom-sqlresultset-insertid" title="dom-SQLResultSet-insertId"><CODE>insertId</CODE></DFN>
  attribute must return the row ID of the row that the
  <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultset">SQLResultSet</A></CODE> object's SQL statement inserted into the
  database, if the statement inserted a row. If the statement inserted
  multiple rows, the ID of the last row must be the one returned. If
  the statement did not insert a row, then the attribute must instead
  raise an <CODE>INVALID_ACCESS_ERR</CODE> exception.</P><P>The <DFN id="dom-sqlresultset-rowsaffected" title="dom-SQLResultSet-rowsAffected"><CODE>rowsAffected</CODE></DFN>
  attribute must return the number of rows that were changed by the
  SQL statement. If the statement did not affected any rows, then the
  attribute must return zero. For "SELECT" statements, this returns
  zero (querying the database doesn't affect any rows).</P><P>The <DFN id="dom-sqlresultset-rows" title="dom-SQLResultSet-rows"><CODE>rows</CODE></DFN>
  attribute must return a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultsetrowlist">SQLResultSetRowList</A></CODE>
  representing the rows returned, in the order returned by the
  database. If no rows were returned, then the object will be empty
  (its <CODE title="dom-SQLResultSetRowList-length"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultsetrowlist-length">length</A></CODE> will
  be zero).</P><PRE class="idl">interface <DFN id="sqlresultsetrowlist">SQLResultSetRowList</DFN> {
  readonly attribute unsigned long <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultsetrowlist-length" title="dom-SQLResultSetRowList-length">length</A>;
  getter <SPAN>any</SPAN> <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultsetrowlist-item" title="dom-SQLResultSetRowList-item">item</A>(in unsigned long index);
};</PRE><P class="note">For the asynchronous API, implementors are
  encouraged to prefetch all the data for
  <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultsetrowlist">SQLResultSetRowList</A></CODE> objects when the object is
  constructed (before the result set callback is invoked), rather than
  on-demand, for better responsiveness. For the synchronous API, an
  on-demand lazy evaluation implementation strategy is encouraged
  instead, for better performance.</P><P><CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlresultsetrowlist">SQLResultSetRowList</A></CODE> objects have a <DFN id="dom-sqlresultsetrowlist-length" title="dom-SQLResultSetRowList-length"><CODE>length</CODE></DFN>
  attribute that must return the number of rows it represents (the
  number of rows returned by the database). This is the <VAR title="dom-SQLResultSetRowList-length"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultsetrowlist-length">length</A></VAR>.</P><P class="note">Fetching the <CODE title="dom-SQLResultSetRowList-length"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultsetrowlist-length">length</A></CODE> might be
  expensive, and authors are thus encouraged to avoid using it (or
  enumerating over the object, which implicitly uses it) where
  possible.</P><P>The object's <SPAN>indices of the supported indexed
  properties</SPAN> are the numbers in the range zero to <SPAN title=""><VAR title="dom-SQLResultSetRowList-length"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultsetrowlist-length">length</A></VAR>-1</SPAN>, unless
  the <VAR title="dom-SQLResultSetRowList-length"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlresultsetrowlist-length">length</A></VAR> is
  zero, in which case there are no <SPAN>supported indexed
  properties</SPAN>.</P><P>The <DFN id="dom-sqlresultsetrowlist-item" title="dom-SQLResultSetRowList-item"><CODE>item(<VAR title="">index</VAR>)</CODE></DFN> attribute must return the row
  with the given index <VAR title="">index</VAR>. If there is no such
  row, then the method must return null.</P><P>Each row must be represented by a native ordered dictionary data
  type. In the JavaScript binding, this must be <CODE>Object</CODE>.
  Each row object must have one property (or dictionary entry) per
  column, with those properties enumerating in the order that these
  columns were returned by the database. Each property must have the
  name of the column and the value of the cell, as they were returned
  by the database.</P><H3 id="errors-and-exceptions"><SPAN class="secno">4.6 </SPAN>Errors and exceptions</H3><P>Errors in the asynchronous database API are reported using
  callbacks that have a <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlerror">SQLError</A></CODE> object as one of their
  arguments.</P><PRE class="idl">interface <DFN id="sqlerror">SQLError</DFN> {
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-unknown" title="dom-SQLException-code-UNKNOWN">UNKNOWN_ERR</A> = 0;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-database" title="dom-SQLException-code-DATABASE">DATABASE_ERR</A> = 1;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-version" title="dom-SQLException-code-VERSION">VERSION_ERR</A> = 2;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-too_large" title="dom-SQLException-code-TOO_LARGE">TOO_LARGE_ERR</A> = 3;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-quota" title="dom-SQLException-code-QUOTA">QUOTA_ERR</A> = 4;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-syntax" title="dom-SQLException-code-SYNTAX">SYNTAX_ERR</A> = 5;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-constraint" title="dom-SQLException-code-CONSTRAINT">CONSTRAINT_ERR</A> = 6;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-timeout" title="dom-SQLException-code-TIMEOUT">TIMEOUT_ERR</A> = 7;
  readonly attribute unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlerror-code" title="dom-SQLError-code">code</A>;
  readonly attribute DOMString <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlerror-message" title="dom-SQLError-message">message</A>;
};</PRE><P>The <DFN id="dom-sqlerror-code" title="dom-SQLError-code"><CODE>code</CODE></DFN> IDL
  attribute must return the most appropriate code from the table
  below.</P><P>The <DFN id="dom-sqlerror-message" title="dom-SQLError-message"><CODE>message</CODE></DFN>
  IDL attribute must return an error message describing the error
  encountered. The message should be localized to the user's
  language.</P><HR><P>Errors in the synchronous database API are reported using
  <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#sqlexception">SQLException</A></CODE> exceptions:</P><PRE class="idl">exception <DFN id="sqlexception">SQLException</DFN> {
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-unknown" title="dom-SQLException-code-UNKNOWN">UNKNOWN_ERR</A> = 0;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-database" title="dom-SQLException-code-DATABASE">DATABASE_ERR</A> = 1;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-version" title="dom-SQLException-code-VERSION">VERSION_ERR</A> = 2;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-too_large" title="dom-SQLException-code-TOO_LARGE">TOO_LARGE_ERR</A> = 3;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-quota" title="dom-SQLException-code-QUOTA">QUOTA_ERR</A> = 4;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-syntax" title="dom-SQLException-code-SYNTAX">SYNTAX_ERR</A> = 5;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-constraint" title="dom-SQLException-code-CONSTRAINT">CONSTRAINT_ERR</A> = 6;
  const unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code-timeout" title="dom-SQLException-code-TIMEOUT">TIMEOUT_ERR</A> = 7;
  unsigned short <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-code" title="dom-SQLException-code">code</A>;
  DOMString <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqlexception-message" title="dom-SQLException-message">message</A>;
};</PRE><P>The <DFN id="dom-sqlexception-code" title="dom-SQLException-code"><CODE>code</CODE></DFN>
  IDL attribute must return the most appropriate code from the table
  below.</P><P>The <DFN id="dom-sqlexception-message" title="dom-SQLException-message"><CODE>message</CODE></DFN> IDL
  attribute must return an error message describing the error
  encountered. The message should be localized to the user's
  language.</P><HR><P>The error codes are as follows:</P><TABLE><THEAD><TR><TH>Constant
     </TH><TH>Code
     </TH><TH>Situation
   </TH></TR></THEAD><TBODY><TR><TD><DFN id="dom-sqlexception-code-unknown" title="dom-SQLException-code-UNKNOWN"><CODE>UNKNOWN_ERR</CODE></DFN>
     </TD><TD><DFN id="dom-sqlerror-code-0" title="dom-sqlerror-code-0">0</DFN>
     </TD><TD>The transaction failed for reasons unrelated to the database
     itself and not covered by any other error code.

    </TD></TR><TR><TD><DFN id="dom-sqlexception-code-database" title="dom-SQLException-code-DATABASE"><CODE>DATABASE_ERR</CODE></DFN>
     </TD><TD><DFN id="dom-sqlerror-code-1" title="dom-sqlerror-code-1">1</DFN>
     </TD><TD>The statement failed for database reasons not covered by any
     other error code.

    </TD></TR><TR><TD><DFN id="dom-sqlexception-code-version" title="dom-SQLException-code-VERSION"><CODE>VERSION_ERR</CODE></DFN>
     </TD><TD><DFN id="dom-sqlerror-code-2" title="dom-sqlerror-code-2">2</DFN>
     </TD><TD>The operation failed because the actual database version was
     not what it should be. For example, a statement found that the
     actual database version no longer matched the <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#concept-database-expected-version" title="concept-database-expected-version">expected version</A>
     of the <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#database">Database</A></CODE> or <CODE><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#databasesync">DatabaseSync</A></CODE> object,
     or the <CODE title="dom-database-changeversion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-changeversion">Database.changeVersion()</A></CODE>
     or <CODE title="dom-database-sync-changeversion"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-database-sync-changeversion">DatabaseSync.changeVersion()</A></CODE>
     methods were passed a version that doesn't match the actual
     database version.

    </TD></TR><TR><TD><DFN id="dom-sqlexception-code-too_large" title="dom-SQLException-code-TOO_LARGE"><CODE>TOO_LARGE_ERR</CODE></DFN>
     </TD><TD><DFN id="dom-sqlerror-code-3" title="dom-sqlerror-code-3">3</DFN>
     </TD><TD>The statement failed because the data returned from the
     database was too large. The SQL "LIMIT" modifier might be useful
     to reduce the size of the result set.

    </TD></TR><TR><TD><DFN id="dom-sqlexception-code-quota" title="dom-SQLException-code-QUOTA"><CODE>QUOTA_ERR</CODE></DFN>
     </TD><TD><DFN id="dom-sqlerror-code-4" title="dom-sqlerror-code-4">4</DFN>
     </TD><TD>The statement failed because there was not enough remaining
     storage space, or the storage quota was reached and the user
     declined to give more space to the database.

    </TD></TR><TR><TD><DFN id="dom-sqlexception-code-syntax" title="dom-SQLException-code-SYNTAX"><CODE>SYNTAX_ERR</CODE></DFN>
     </TD><TD><DFN id="dom-sqlerror-code-5" title="dom-sqlerror-code-5">5</DFN>
     </TD><TD>The statement failed because of a syntax error, or the number
     of arguments did not match the number of <CODE title="">?</CODE>
     placeholders in the statement, or the statement tried to use a
     statement that is not allowed, such as <CODE title="">BEGIN</CODE>, <CODE title="">COMMIT</CODE>, or <CODE title="">ROLLBACK</CODE>, or the statement tried to use a verb
     that could modify the database but the transaction was read-only.

    </TD></TR><TR><TD><DFN id="dom-sqlexception-code-constraint" title="dom-SQLException-code-CONSTRAINT"><CODE>CONSTRAINT_ERR</CODE></DFN>
     </TD><TD><DFN id="dom-sqlerror-code-6" title="dom-sqlerror-code-6">6</DFN>
     </TD><TD>An <CODE title="">INSERT</CODE>, <CODE title="">UPDATE</CODE>, or <CODE title="">REPLACE</CODE>
     statement failed due to a constraint failure. For example,
     because a row was being inserted and the value given for the
     primary key column duplicated the value of an existing row.

    </TD></TR><TR><TD><DFN id="dom-sqlexception-code-timeout" title="dom-SQLException-code-TIMEOUT"><CODE>TIMEOUT_ERR</CODE></DFN>
     </TD><TD><DFN id="dom-sqlerror-code-7" title="dom-sqlerror-code-7">7</DFN>
     </TD><TD>A lock for the transaction could not be obtained in a
     reasonable time.

  </TD></TR></TBODY></TABLE><H2 id="web-sql"><SPAN class="secno">5 </SPAN>Web SQL</H2><P>User agents must implement the SQL dialect supported by Sqlite 3.6.19.</P><P>When converting bound arguments to SQL data types, the JavaScript
  ToPrimitive operator must be applied to obtain the raw value to be
  processed. <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsECMA262">[ECMA262]</A>.</P><H2 id="disk-space"><SPAN class="secno">6 </SPAN>Disk space</H2><P>User agents should limit the total amount of space allowed for
  databases.
  
  </P><P>User agents should guard against sites storing data under the
  origins other affiliated sites, e.g. storing up to the limit in
  a1.example.com, a2.example.com, a3.example.com, etc, circumventing
  the main example.com storage limit.</P><P>User agents may prompt the user when quotas are reached, allowing
  the user to grant a site more space. This enables sites to store
  many user-created documents on the user's computer, for
  instance.</P><P>User agents should allow users to see how much space each domain
  is using.</P><P>A mostly arbitrary limit of five megabytes per
  <SPAN>origin</SPAN> is recommended. Implementation feedback is
  welcome and will be used to update this suggestion in the
  future.</P><H2 id="privacy"><SPAN class="secno">7 </SPAN>Privacy</H2><H3 id="user-tracking"><SPAN class="secno">7.1 </SPAN>User tracking</H3><P>A third-party advertiser (or any entity capable of getting
  content distributed to multiple sites) could use a unique identifier
  stored in its
  client-side databases
  
  
  to track a user across multiple sessions, building a profile of the
  user's interests to allow for highly targeted advertising. In
  conjunction with a site that is aware of the user's real identity
  (for example an e-commerce site that requires authenticated
  credentials), this could allow oppressive groups to target
  individuals with greater accuracy than in a world with purely
  anonymous Web usage.</P><P>There are a number of techniques that can be used to mitigate the
  risk of user tracking:</P><DL><DT>Blocking third-party storage</DT>
   <DD>

    <P>User agents may restrict access to
    the database objects
    
    
    to scripts originating at the domain of the top-level document of
    the <SPAN>browsing context</SPAN>, for instance denying access to
    the API for pages from other domains running in
    <CODE>iframe</CODE>s.</P>

   </DD>

   <DT>Expiring stored data</DT>
   <DD>

    <P>User agents may, if so configured by the user, automatically
    delete stored data after a period of time.</P>


    <P>This can restrict the ability of a site to track a user, as the
    site would then only be able to track the user across multiple
    sessions when he authenticates with the site itself (e.g. by
    making a purchase or logging in to a service).</P>

    <P>However, this also reduces the usefulness of the API as a
    long-term storage mechanism. It can also put the user's data at
    risk, if the user does not fully understand the implications of
    data expiration.</P>


   </DD>

   <DT>Treating persistent storage as cookies</DT>
   <DD>

    <P>If users attempt to protect their privacy by clearing cookies
    without also clearing data stored in the
    relevant databases,
    
    sites can defeat those attempts by using the two features as
    redundant backup for each other. User agents should present the
    interfaces for clearing these in a way that helps users to
    understand this possibility and enables them to delete data in all
    persistent storage features simultaneously. <A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#refsCOOKIES">[COOKIES]</A></P>

   </DD>

   <DT>Site-specific white-listing of access to
   databases
   
   
   </DT>
   <DD>

    <P>User agents may require the user to authorize access to
    databases before a site can use the feature.</P>
    
    

   </DD>

   <DT>Origin-tracking of stored data</DT>
   <DD>

    <P>User agents may record the <SPAN title="origin">origins</SPAN>
    of sites that contained content from third-party origins that
    caused data to be stored.</P>

    <P>If this information is then used to present the view of data
    currently in persistent storage, it would allow the user to make
    informed decisions about which parts of the persistent storage to
    prune. Combined with a blacklist ("delete this data and prevent
    this domain from ever storing data again"), the user can restrict
    the use of persistent storage to sites that he trusts.</P>

   </DD>

   <DT>Shared blacklists</DT>
   <DD>

    <P>User agents may allow users to share their persistent storage
    domain blacklists.</P>

    <P>This would allow communities to act together to protect their
    privacy.</P>

   </DD>

  </DL><P>While these suggestions prevent trivial use of this API for user
  tracking, they do not block it altogether. Within a single domain, a
  site can continue to track the user during a session, and can then
  pass all this information to the third party along with any
  identifying information (names, credit card numbers, addresses)
  obtained by the site. If a third party cooperates with multiple
  sites to obtain such information, a profile can still be
  created.</P><P>However, user tracking is to some extent possible even with no
  cooperation from the user agent whatsoever, for instance by using
  session identifiers in URLs, a technique already commonly used for
  innocuous purposes but easily repurposed for user tracking (even
  retroactively). This information can then be shared with other
  sites, using using visitors' IP addresses and other user-specific
  data (e.g. user-agent headers and configuration settings) to combine
  separate sessions into coherent user profiles.</P><H3 id="sensitivity-of-data"><SPAN class="secno">7.2 </SPAN>Sensitivity of data</H3><P>User agents should treat persistently stored data as potentially
  sensitive; it's quite possible for e-mails, calendar appointments,
  health records, or other confidential documents to be stored in this
  mechanism.</P><P>To this end, user agents should ensure that when deleting data,
  it is promptly deleted from the underlying storage.</P><H2 id="security"><SPAN class="secno">8 </SPAN>Security</H2><H3 id="dns-spoofing-attacks"><SPAN class="secno">8.1 </SPAN>DNS spoofing attacks</H3><P>Because of the potential for DNS spoofing attacks, one cannot
  guarantee that a host claiming to be in a certain domain really is
  from that domain. To mitigate this, pages can use SSL. Pages using
  SSL can be sure that only pages using SSL that have certificates
  identifying them as being from the same domain can access their
  databases.
  
  </P><H3 id="cross-directory-attacks"><SPAN class="secno">8.2 </SPAN>Cross-directory attacks</H3><P>Different authors sharing one host name, for example users
  hosting content on <CODE>geocities.com</CODE>, all share one
  set of databases.
  
  There is no feature to restrict the access by pathname. Authors on
  shared hosts are therefore recommended to avoid using these
  features, as it would be trivial for other authors to read the data
  and overwrite it.</P><P class="note">Even if a path-restriction feature was made
  available, the usual DOM scripting security model would make it
  trivial to bypass this protection and access the data from any
  path.</P><H3 id="implementation-risks"><SPAN class="secno">8.3 </SPAN>Implementation risks</H3><P>The two primary risks when implementing these persistent storage
  features are letting hostile sites read information from other
  domains, and letting hostile sites write information that is then
  read from other domains.</P><P>Letting third-party sites read data that is not supposed to be
  read from their domain causes <EM>information leakage</EM>, For
  example, a user's shopping wishlist on one domain could be used by
  another domain for targeted advertising; or a user's
  work-in-progress confidential documents stored by a word-processing
  site could be examined by the site of a competing company.</P><P>Letting third-party sites write data to the persistent storage of
  other domains can result in <EM>information spoofing</EM>, which is
  equally dangerous. For example, a hostile site could add items to a
  user's wishlist; or a hostile site could set a user's session
  identifier to a known ID that the hostile site can then use to track
  the user's actions on the victim site.</P><P>Thus, strictly following the <SPAN>origin</SPAN> model described
  in this specification is important for user security.</P><H3 id="sql-and-user-agents"><SPAN class="secno">8.4 </SPAN>SQL and user agents</H3><P>User agent implementors are strongly encouraged to audit all
  their supported SQL statements for security implications. For
  example, <CODE title="">LOAD DATA INFILE</CODE> is likely to pose
  security risks and there is little reason to support it.</P><P>In general, it is recommended that user agents not support
  features that control how databases are stored on disk. For example,
  there is little reason to allow Web authors to control the character
  encoding used in the disk representation of the data, as all data in
  JavaScript is implicitly UTF-16.</P><H3 id="sql-injection"><SPAN class="secno">8.5 </SPAN>SQL injection</H3><P>Authors are strongly recommended to make use of the <CODE title="">?</CODE> placeholder feature of the <CODE title="dom-sqltransaction-executeSql"><A href="http://www.w3.org/TR/2009/WD-webdatabase-20091222/#dom-sqltransaction-executesql">executeSql()</A></CODE> method,
  and to never construct SQL statements on the fly.</P><!--START vCard--><!--START vEvent--><H2 class="no-num" id="references">References</H2><!--REFS--><!--END vCard--><!--END vEvent--><P>All references are normative unless marked "Non-normative".</P><!--START vCard--><!--START vEvent--><DL><DT id="refsCOOKIES">[COOKIES]</DT>
   <!--
   <dd><cite><a href="http://www.ietf.org/rfc/rfc2109.txt">HTTP State
   Management Mechanism</a></cite>, D. Kristol, L. Montulli. IETF,
   February 1997.</dd>
   <dd><cite><a href="http://www.ietf.org/rfc/rfc2965.txt">HTTP State Management
   Mechanism</a></cite>, D. Kristol, L. Montulli. IETF, October 2000.</dd>
   -->
   <DD><CITE><A href="http://tools.ietf.org/html/draft-abarth-cookie">HTTP State
   Management Mechanism</A></CITE>, A. Barth. IETF, August 2009.</DD>

   <DT id="refsDOMCORE">[DOMCORE]</DT>
   <DD><CITE><A href="http://www.w3.org/TR/DOM-Level-3-Core/">Document
   Object Model (DOM) Level 3 Core Specification</A></CITE>, A. Le
   Hors, P. Le Hegaret, L. Wood, G. Nicol, J. Robie, M. Champion,
   S. Byrnes. W3C, April 2004.</DD>
   <!--
   <dd><cite><a href="http://simon.html5.org/specs/web-dom-core">Web
   DOM Core</a></cite>, S. Pieters. W3C, June 2009.</dd>
   -->

   <DT id="refsECMA262">[ECMA262]</DT>
   <DD><CITE><A href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript
   Language Specification</A></CITE>. ECMA, December 1999.</DD>

   <DT id="refsHTML5">[HTML5]</DT>
   <!--
   <dd><cite><a href="http://www.w3.org/TR/html5/">HTML5</a></cite>,
   I. Hickson, D. Hyatt. W3C, April 2009.</dd>
   <dd><cite><a
   href="http://www.w3.org/html/wg/html5/">HTML5</a></cite>,
   I. Hickson, D. Hyatt. W3C, August 2009.</dd>
   -->
   <DD><CITE><A href="http://www.whatwg.org/specs/web-apps/current-work/">HTML5</A></CITE>,
   I. Hickson. WHATWG, August 2009.</DD>

   <DT id="refsRFC2119">[RFC2119]</DT>
   <DD><CITE><A href="http://www.ietf.org/rfc/rfc2119.txt">Key words for use in
   RFCs to Indicate Requirement Levels</A></CITE>, S. Bradner. IETF, March
   1997.</DD>

   <DT id="refsSQL">[SQL]</DT>
   <DD>The precise dialect has not yet been specified.</DD>

   <DT id="refsWEBIDL">[WEBIDL]</DT>
   <!--
   <dd><cite><a href="http://www.w3.org/TR/WebIDL/">Web
   IDL</a></cite>, C. McCormack. W3C, December 2008.</dd>
   -->
   <DD><CITE><A href="http://dev.w3.org/2006/webapi/WebIDL/">Web
   IDL</A></CITE>, C. McCormack. W3C, July 2009.</DD>

  </DL><!--END vCard--><!--END vEvent-->
</BODY></HTML>